#include <iostream>
#include <map>

using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        auto n   = s.size();
        string p = "";
        auto max = 0U;
        for (auto i = 0U; i < n; i++) {
            auto find = p.find(s[i]);
            // cout << "deubg 1 find: " << find << ", s[i]: " << s[i] << ", p: "
            // << p
            // <<endl;
            if (find == string::npos) {
                p += s[i];
            } else {
                if (p.size() > max)
                    max = p.size();

                p.erase(0, find + 1);
                p += s[i];
            }
        }

        return p.size() > max ? p.size() : max;
    }
};

int main(void) {
    std::cout << "最长不重复子串longest substring" << std::endl;

    auto s = Solution().lengthOfLongestSubstring("dvdf");
    cout << s << endl;

    s = Solution().lengthOfLongestSubstring("bbbbb");
    cout << s << endl;

    s = Solution().lengthOfLongestSubstring("pwwkew");
    cout << s << endl;
    return 0;
}